import requests
import tempfile
from scapy.all import rdpcap

def main() -> dict:
    try:
        # 业务逻辑
        pcap_url = "https://mp-cdbaaef4-2954-4e60-b694-5fa009269a02.cdn.bspapp.com/cloudstorage/sql_injection_0.pcap"
        response = requests.get(pcap_url)
        response.raise_for_status()
        # 写入临时文件
        with tempfile.NamedTemporaryFile(delete=False, suffix=".pcap") as tmp_file:
            tmp_file.write(response.content)
            tmp_path = tmp_file.name

        # 使用 scapy 读取
        packets = rdpcap(tmp_path)

        # 提取前 100 个包的摘要
        summaries = [pkt.summary() for pkt in packets[:1000]]

        result = {
            "packet_summaries": summaries
        }
        print(result)
        return {"result": result}
    except Exception as e:
        print(f"请求失败: {e}")
        return {"result": str(e)}

if __name__ == "__main__":
    main()  # 正确调用